package course.myra.filetest;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestIO {

	public static void main(String[] args) {
		test01();
	}
	
	/**
	 * 
	 */
	private static void test01() {
		//实例化输入流和输出流
		FileInputStream fis=null;
		FileOutputStream fos = null ;
		//File fileIn = new File("d:/demo/in.txt");
		//File fileOut =new File("d:/demo/out.txt");
		
		try {
			//实例化输入流和输出流
			fis = new FileInputStream("d:/demo/in.txt");
			fos = new FileOutputStream("d:/demo/out.txt");
			
			//获取输入流的数组
			byte[] bin;
			//定义获取长度
			int length = -1;
			
			do {
				//每次获取数据前初始化数组
				bin = new byte[100];
				//本次获取数组的 长度
				length = fis.read(bin);
				//在控制台输出
				String string = new String(bin);
				System.out.println(string);
				
				//输出到文件
				fos.write(bin);
				
			}while(length>-1);
			System.out.println("文件读取成功");
			System.out.println("文件写出成功");
			fis.close();
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
		
	}


